/**
 * 作者: wgx
 * 日期: 2024-11-20 15:21:28
 * 备注: 用户兽潮来袭模块信息表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserMonsterTideInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserMonsterTideInfoModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 用户ID
    protected int lastMonsterTideId; // 上一场战斗的兽潮id
    protected int lastResult; // 上一场战斗的结果 (0-失败,.1-胜利)
    protected long lastTime; // 上一场战斗的时间
    protected int nextMonsterTideId; // 下一场战斗的兽潮id
    protected long nextTime; // 下一场战斗的时间
    protected long lastMyPower; // 打上一场时我方的战力
    protected long minTime; // 最小战斗时间

    public void reset() {
    }

    protected String getKey() {
        return "UserMonsterTideInfo." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_monster_tide_info"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 用户ID
        obj.put("lastMonsterTideId", lastMonsterTideId); // 上一场战斗的兽潮id
        obj.put("lastResult", lastResult); // 上一场战斗的结果 (0-失败,.1-胜利)
        obj.put("lastTime", lastTime); // 上一场战斗的时间
        obj.put("nextMonsterTideId", nextMonsterTideId); // 下一场战斗的兽潮id
        obj.put("nextTime", nextTime); // 下一场战斗的时间
        obj.put("lastMyPower", lastMyPower); // 打上一场时我方的战力
        obj.put("minTime", minTime); // 最小战斗时间
        return obj;
    }

    public PBUserMonsterTideInfo.Builder takeInitBuilder() {
        PBUserMonsterTideInfo.Builder sb = PBUserMonsterTideInfo.newBuilder();
        if (lastMonsterTideId != 0) {
            sb.setLastMonsterTideId(lastMonsterTideId);
        }
        if (lastResult != 0) {
            sb.setLastResult(lastResult);
        }
        if (lastTime != 0) {
            sb.setLastTime(lastTime);
        }
        if (nextMonsterTideId != 0) {
            sb.setNextMonsterTideId(nextMonsterTideId);
        }
        if (nextTime != 0) {
            sb.setNextTime(nextTime);
        }
        if (lastMyPower != 0) {
            sb.setLastMyPower(lastMyPower);
        }
        return sb;
    }

    public PBUserMonsterTideInfo.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserMonsterTideInfo.Builder sb = PBUserMonsterTideInfo.newBuilder();
        if (isFieldUpdate("lastMonsterTideId")) {
            sb.setLastMonsterTideId(lastMonsterTideId);
        }
        if (isFieldUpdate("lastResult")) {
            sb.setLastResult(lastResult);
        }
        if (isFieldUpdate("lastTime")) {
            sb.setLastTime(lastTime);
        }
        if (isFieldUpdate("nextMonsterTideId")) {
            sb.setNextMonsterTideId(nextMonsterTideId);
        }
        if (isFieldUpdate("nextTime")) {
            sb.setNextTime(nextTime);
        }
        if (isFieldUpdate("lastMyPower")) {
            sb.setLastMyPower(lastMyPower);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getLastMonsterTideId() {
        return lastMonsterTideId;
    }

    public void putLastMonsterTideId(int lastMonsterTideId) {
        if (this.lastMonsterTideId != lastMonsterTideId) {
            this.lastMonsterTideId = lastMonsterTideId;
            updateRedisHashField(getKey(), "lastMonsterTideId", this.lastMonsterTideId);
        }
    }

    public void addLastMonsterTideId(int value) {
        this.lastMonsterTideId += value;
        updateRedisHashField(getKey(), "lastMonsterTideId", this.lastMonsterTideId);
    }

    public int getLastResult() {
        return lastResult;
    }

    public void putLastResult(int lastResult) {
        if (this.lastResult != lastResult) {
            this.lastResult = lastResult;
            updateRedisHashField(getKey(), "lastResult", this.lastResult);
        }
    }

    public void addLastResult(int value) {
        this.lastResult += value;
        updateRedisHashField(getKey(), "lastResult", this.lastResult);
    }

    public long getLastTime() {
        return lastTime;
    }

    public void putLastTime(long lastTime) {
        if (this.lastTime != lastTime) {
            this.lastTime = lastTime;
            updateRedisHashField(getKey(), "lastTime", this.lastTime);
        }
    }

    public void addLastTime(long value) {
        this.lastTime += value;
        updateRedisHashField(getKey(), "lastTime", this.lastTime);
    }

    public int getNextMonsterTideId() {
        return nextMonsterTideId;
    }

    public void putNextMonsterTideId(int nextMonsterTideId) {
        if (this.nextMonsterTideId != nextMonsterTideId) {
            this.nextMonsterTideId = nextMonsterTideId;
            updateRedisHashField(getKey(), "nextMonsterTideId", this.nextMonsterTideId);
        }
    }

    public void addNextMonsterTideId(int value) {
        this.nextMonsterTideId += value;
        updateRedisHashField(getKey(), "nextMonsterTideId", this.nextMonsterTideId);
    }

    public long getNextTime() {
        return nextTime;
    }

    public void putNextTime(long nextTime) {
        if (this.nextTime != nextTime) {
            this.nextTime = nextTime;
            updateRedisHashField(getKey(), "nextTime", this.nextTime);
        }
    }

    public void addNextTime(long value) {
        this.nextTime += value;
        updateRedisHashField(getKey(), "nextTime", this.nextTime);
    }

    public long getLastMyPower() {
        return lastMyPower;
    }

    public void putLastMyPower(long lastMyPower) {
        if (this.lastMyPower != lastMyPower) {
            this.lastMyPower = lastMyPower;
            updateRedisHashField(getKey(), "lastMyPower", this.lastMyPower);
        }
    }

    public void addLastMyPower(long value) {
        this.lastMyPower += value;
        updateRedisHashField(getKey(), "lastMyPower", this.lastMyPower);
    }

    public long getMinTime() {
        return minTime;
    }

    public void putMinTime(long minTime) {
        if (this.minTime != minTime) {
            this.minTime = minTime;
            updateRedisHashField(getKey(), "minTime", this.minTime);
        }
    }

    public void addMinTime(long value) {
        this.minTime += value;
        updateRedisHashField(getKey(), "minTime", this.minTime);
    }

}